package lambda;

import java.util.Comparator;
import java.util.function.Consumer;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/25 10:19
 * @Copyright 博为峰
 */
public class MethodRef {
    public static void main(String[] args) {
//        m1();
        m2();
    }

    private static void m2() {
        Comparator<Integer> a = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
//                return o1.compareTo(o2);
                return o1.intValue() - o2.intValue();
            }
        };

        a = (o1, o2) -> o1.intValue() - o2.intValue();
        //类::实例方法名
        a = Integer::compareTo;
        //类::静态方法名
        a = Integer::compare;

        System.out.println(a.compare(6, 9));
    }

    //对象::实例方法名
    private static void m1() {
        Consumer<String> consumer = new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };

        consumer = s -> System.out.println(s);

        consumer = System.out::println;//方法引用

        consumer.accept("abc");
    }
}
